// pages/index/infor/location/location.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    locationid:{},
    phone :{},
    id:"",
    list:[{
        username:"陆保哲",
        locationid:"123",
        location:"广西民族大学相思湖学院文馨公寓（B6）6610 宿舍",
        replenish:"广西民族大学相思湖学院文馨公寓（B6）6610 宿舍",
        phone:"15978071679",
        defaultlocation:false},
        {
          username:"陆保哲",
          locationid:"456",
          location:"广西民族大学相思湖学院文馨公寓（B6）6610 宿舍",
          replenish:"广西民族大学相思湖学院文馨公寓（B6）6610 宿舍",
          phone:"15978071679",
          defaultlocation:true},
      ],
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.popup = this.selectComponent("#popup");
    //根据手机号获取地址信息
    let that=this
    let phone = options.phone ;
   that.data.phone =phone 
   console.log( phone )
    wx.request({
      url: '',
      method:"POST",
      header:{
        "cookie":wx.getStorageSync('sessionid'),
        // "Authorization":wx.getStorageSync('session')
      }, 
     data:{
       "phone ":phone ,
     },
     success (res) {
      that.data.list=res.data.list
      console.log(res)
  
    }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  //修改地址
  modifylocation:function(e){
    var i = e.currentTarget.dataset.smile;
    let that=this
   that.data.locationid=that.data.list[i].locationid
let locationid=that.data.locationid
// console.log(that.data.locationid)
    wx.navigateTo({
      url: '/pages/index/infor/location/modifylocation/modifylocation?locationid='+[locationid],
    })
  },
  //新建地址
  addlocation:function(){
    let locationid=""
    wx.navigateTo({
      url: '/pages/index/infor/location/addlocation/addlocation',
    })
  },
  delete:function(e){
      this.popup.showPopup();
      this.setData({
        id:e.target.id
      })
    },
    //取消删除
    merchant() {
      this.popup.hidePopup();
    },
    //删除
    customer() {
      let that = this
      let phone = that.data.phone
  
      this.popup.hidePopup();
      wx.request({
        url: '',
        method:"POST",
       data:{
         phone:that.data.phone,
         id:that.data.id,
        delete:"delete",
       },
       success (res) {
    
      }
      })
    
    },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }

})